package com.bdzl.credit.controller;

import com.bdzl.credit.service.CreditService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.CreditDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import com.bdzl.pub.vo.loan.CreditVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 客户个人征信查询缓存信息表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:23:42
 */

@Controller
@RequestMapping("/bdzl/credit")
public class CreditController extends BaseController {
	@Autowired
	private CreditService creditService;

	@GetMapping()
	String Credit(){
	    return "bdzl/credit/credit";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<CreditVO> creditList = creditService.CreditVOlist(query);
		int total = creditService.count(query);
		PageUtils pageUtils = new PageUtils(creditList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/credit/add";
	}

	@PostMapping("/edit")
	@ResponseBody
	CreditDO edit(@RequestBody CreditDO credit){
		credit = creditService.get(credit.getCreditId());
	    return credit;
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( CreditDO credit){
		if(creditService.save(credit)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( CreditDO credit){
		creditService.update(credit);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer creditId){
		if(creditService.remove(creditId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] creditIds){
		creditService.batchRemove(creditIds);
		return R.ok();
	}
	/**
	* @Description: TODO 根据身份证号查询是否有征信数据
	* @param cardId 身份证号
	* @return: com.bdzl.pub.entity.loan.CreditDO
	* @Author: Ming
	* @Date: 2021/5/18 10:35
	*/
	@PostMapping("/getCreditByCardId")
	@ResponseBody
	public CreditVO getCreditByCardId(@RequestParam("cardId") String cardId){
		return creditService.getCreditByCardId(cardId);
	}
}
